package com.zbd.microservices.service;

import java.io.Serializable;

import javax.transaction.Transactional;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * 鼻屎SERVICE
 * @author 赵宝东
 */
public class BaseService<T, ID extends Serializable> {
	protected PagingAndSortingRepository<T, ID> repository;

	protected void setRepository(PagingAndSortingRepository<T, ID> repository) {
		this.repository = repository;
	}

	@Transactional
	public T save(T t) {
		return repository.save(t);
	}

	@Transactional
	public void delete(T t) {
		repository.delete(t);
	}

	@Cacheable(value = "finaAll", keyGenerator = "DKeyGenerator")
	public Iterable<T> findAll() {	
		return repository.findAll();
	}

	@Cacheable(value = "finaAllByIds", keyGenerator = "DKeyGenerator")
	public void findAllByIds(Iterable<ID> ids) {
		repository.findAll(ids);
	}


	@Cacheable(value = "getOne", keyGenerator = "DKeyGenerator")
	public T findOne(ID id) {
		return repository.findOne(id);
	}
}